<?php
	namespace Common\Logic;
	use Common\Model\UserGalleryActionModel;
	class UserGalleryActionLogic extends UserGalleryActionModel{
		/*
		* Function:		getUserGalleryActionList
		* Description:	画廊动作列表
		* @param:		$page string 起始页
						$filter array 过滤数组
						$pageSize string 每页显示条数
		*/
		public function getUserGalleryActionList($page=1,$filter = '',$pageSize=20){
			$conditon = $this->getUserGalleryActionFilter($filter);
			return $this->alias('a')->join('left join gallerys as b on a.tid=b.id')->field('a.*')->where($conditon)->order('a.id desc')->limit(($page-1)*$pageSize,$pageSize)->select();
		}
		
		/*
		* Function:get:	getUserGalleryActionFilter
		* Description:	画廊动作列表搜索过滤项
		* @param:		$filter array 过滤数组
		*/
		public function getUserGalleryActionFilter($filter = ''){
			$conditon = array();
         $conditon['a.status'] = 1;
         $conditon['b.status'] = 1;
         $conditon['b.is_deleted'] = 0;
			if(!empty($filter['type'])){
				$conditon['a.type'] = $filter['type'];
			}
			if(!empty($filter['user_id'])){
				$conditon['a.user_id'] = $filter['user_id'];
			}
			return $conditon;
		}
		
		/*
		* Function:get:	getUserGalleryActionCount
		* Description:	画廊动作列表总数
		* @param:		$filter array 过滤数组
		*/
		public function getUserGalleryActionCount($filter = ''){
			$conditon = $this->getUserGalleryActionFilter($filter);
			return $this->alias('a')->join('left join gallerys as b on a.tid=b.id')->where($conditon)->count();
		}
		
		/*
		* Function:		addUserGalleryAction
		* Description:	增加画廊动作
		* @param:		$data array 增加的数组
		*/
		public function addUserGalleryAction($data){
			return $this->add($data);
		}
		
		/*
		* Function:		getUserGalleryActionInfo
		* Description:	获取画廊动作信息 by row
		* @param:		$id int ID
		*/
		public function getUserGalleryActionInfo($id){
			return $this->where(array('id'=>$id))->find();
		}
		
		/*
		* Function:		updateUserGalleryAction
		* Description:	更新画廊动作
		* @param:		$data array 更新的数组
		*/
		public function updateUserGalleryAction($data){
			return $this->save($data);
		}
		
		/*
		* Function:		deleteUserGalleryAction
		* Description:	删除画廊动作
		* @param:		$id int ID
		*/
		public function deleteUserGalleryAction($id){
			return $this->where(array('id'=>$id))->delete();
		}

		/*
		* Function:		getUserGalleryActionSum
		* Description:	更新画廊动作
		* @param:		$data array 更新的数组
		*/
		public function getUserGalleryActionSum($tid = '',$type = 1){
			return $this->where(['status'=>1,'tid'=>$tid,'type'=>$type])->count();
		}
	}
?>